// Copyright 2011, Kitware, Inc.
#include <Python.h>

#include <stdio.h>

// Declare function that we're going to use (belongs in the .h)
static PyObject* cdemo_nativeprint(PyObject *self, PyObject *args);
PyMODINIT_FUNC initcdemo(void);

// Enumerate the functions attached to the module
static PyMethodDef CDemoMethods[] = {
    {"nativeprint",  cdemo_nativeprint, METH_VARARGS,
     "Print natively."},
    {NULL, NULL, 0, NULL}        /* Sentinel */
};

// The __init__ function
PyMODINIT_FUNC
initcdemo(void)
{
  PyObject *m;

  m = Py_InitModule("cdemo", CDemoMethods);
  if (m == NULL)
    return;
}

// Function for printing natively using printf
static PyObject *
cdemo_nativeprint(PyObject *self, PyObject *args)
{
  const char *str;
  int sts;

  if (!PyArg_ParseTuple(args, "s", &str))
    {
    return NULL;
    }
  printf("%s", str);
  return Py_BuildValue("");
}
